package com.yanqu.road.dao.impl.activity.shuihucard;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.shuihu.config.ShuiHuCombConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ShuiHuCombConfigDaoImpl extends TempDao {

    public static String getShuiHuCombConfigSql = "select * from t_s_activity_shuihu_comb where activityId = ?";

    public Map<Integer, ShuiHuCombConfig> getShuiHuCombConfigMap(int activityId) {
        Map<Integer, ShuiHuCombConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getShuiHuCombConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ShuiHuCombConfig shuiHuCombConfig = new ShuiHuCombConfig();
                shuiHuCombConfig.setId(rs.getInt("id"));
                shuiHuCombConfig.setCondition(rs.getString("condition"));
                shuiHuCombConfig.setReward(rs.getString("reward"));
                shuiHuCombConfig.setMaxTimes(rs.getInt("maxTimes"));
                shuiHuCombConfig.setName(rs.getString("name"));
                shuiHuCombConfig.setSort(rs.getInt("sort"));
                map.put(shuiHuCombConfig.getId(), shuiHuCombConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
